package rrrmai.viewbinder;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.jakewharton.rxbinding2.view.RxView;
import com.xgggh.rrrmai.R;
import com.xgggh.rrrmai.databinding.ContactEmptyBinding;

import java.util.concurrent.TimeUnit;

import me.drakeet.multitype.ItemViewBinder;
import rrrmai.activity.FollowActivity;

/**
 * Created by summer on 2018/2/28.
 */
public class ContactEmptyViewBinder extends ItemViewBinder<ContactEmpty, ContactEmptyViewBinder.ViewHolder> {

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        ContactEmptyBinding binding= DataBindingUtil.inflate(inflater,R.layout.contact_empty,parent,false);
        return new ContactEmptyViewBinder.ViewHolder(binding.getRoot());
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull ContactEmpty contact) {
        ContactEmptyBinding binding= DataBindingUtil.getBinding(holder.itemView);
        binding.setContactEmpty(contact);
        RxView.clicks(binding.follow)
                .throttleFirst(200, TimeUnit.MILLISECONDS)
                .subscribe(new io.reactivex.functions.Consumer<Object>() {
                    @Override
                    public void accept(Object o) throws Exception {
                        Intent intent = new Intent(holder.itemView.getContext(), FollowActivity.class);
                        holder.itemView.getContext().startActivity(intent);
                    }
                });
        /*RxCompoundButton.toggle(binding.follow)
                .accept(new Consumer<>() {
                });*/
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        ViewHolder(View itemView) {
            super(itemView);
        }
    }
}
